package com.glq1218.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.glq1218.domain.entity.User;
import com.glq1218.domain.vo.PageParamsVo;
import com.glq1218.domain.vo.PageVo;
import com.glq1218.mapper.UserMapper;
import com.glq1218.response.ResponseResult;
import com.glq1218.service.UserService;
import org.springframework.stereotype.Service;

/**
 * (MwUser)表服务实现类
 *
 * @author glq1218
 * @since 2022-10-14 22:30:55
 */
@Service("userService")
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Override
    public User getByUsername(String username) {
        LambdaQueryWrapper<User> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper
                .eq(User::getUsername, username).or()
                .eq(User::getPhone, username).or()
                .eq(User::getEmail, username);
        return getOne(lambdaQueryWrapper);
    }

    @Override
    public User getByEmail(String email) {
        LambdaQueryWrapper<User> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(User::getEmail, email);
        return getOne(lambdaQueryWrapper);
    }

    @Override
    public User getByPhone(String phone) {
        LambdaQueryWrapper<User> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(User::getPhone, phone);
        return getOne(lambdaQueryWrapper);
    }

    @Override
    public ResponseResult<PageVo<User>> listUser(PageParamsVo pageParamsVo) {
        Page<User> page = new Page<>(pageParamsVo.getPageNum(), pageParamsVo.getPageSize());
        page(page);
        return ResponseResult.success(new PageVo<>(page.getTotal(), page.getRecords()));
    }
}

